
import 'package:shimo_app/bus/protocol/protocol.dart';

import '../frame/frame.dart';
import '../struct/message.dart';
import '../struct/request_id.dart';

class Init extends Protocol {
  bool _hasStart = false;

  @override
  AsyncResult handleAsyncMessage(MessageBean message) {
    if (message.messageId == MessageId.MSG_REPORT_BEGIN) {
      _hasStart = true;
      print("initialization begin");
      return AsyncResult.WAIT;
    }
    if (message.messageId == MessageId.MSG_REPORT_END) {
      message.message.popByte();
      if (_hasStart) {
        return AsyncResult.DONE;
      }
      return AsyncResult.WAIT;
    }
    return AsyncResult.WAIT;
  }

  @override
  bool handleSyncReply(Frame reply) {
    return true;
  }

  @override
  bool isTimeConsuming() {
    return true;
  }

  @override
  int setProcessTimeout() {
    return 4 * 60;
  }

  @override
  RequestId setRequestId() {
    return RequestId.REQ_INIT;
  }
}
